home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 201-220 / scopedisk211 / coldboot / coldboot.a next >
Encoding:
Text File  |  1995-03-20  |  8.6 KB  |  301 lines

  1. ;
  2. ;    @(#)    ColdBoot.a    v1.03(0)    5-Mar-91    pdd
  3. ;
  4. ;        This program will cold-boot the Amiga, trashing any memory-
  5. ;        resident stuff that may try to survive the boot, giving you
  6. ;        maximum memory on the reboot without having  to  power  off
  7. ;        the Amiga.
  8. ;
  9. ; -------------------------------------------------------------------------
  10. ;
  11. ;    Edit history:
  12. ;
  13. ;      1-Mar-91 1.00(0)P    Began working on program.
  14. ;      3-Mar-91 1.00(0)    First working version of program.
  15. ;      3-Mar-91 1.01(0)    Made requester look more reasonable.
  16. ;      5-Mar-91 1.02(0)    Added workbench interface.
  17. ;      5-Mar-91 1.03(0)    Removed global storage; code is now pure.
  18. ;
  19. ; -------------------------------------------------------------------------
  20. ;
  21.  
  22. ;
  23. ; ----- Define a section.  For our purposes, we only need one.
  24. ;
  25.  
  26.     SECTION CODE
  27.  
  28. ;
  29. ; ----- Now include the necessary files.
  30. ;
  31.  
  32.     INCLUDE "exec/types.i"        ;To define various data types.
  33.     INCLUDE "libraries/dosextens.i"    ;To get at our process info.
  34.     INCLUDE "exec/alerts.i"        ;So we can bring up GURUs.
  35.     INCLUDE "exec/execbase.i"    ;So we can trash it.
  36.     INCLUDE "intuition/intuition.i"    ;So we can bring up a requester.
  37.  
  38. ;
  39. ; ----- Define the external symbols we will be using in this program.
  40. ;
  41.  
  42.     XREF    _AbsExecBase
  43.  
  44.     XREF    _LVOOpenLibrary
  45.     XREF    _LVOCloseLibrary
  46.     XREF    _LVOAlert
  47.     XREF    _LVODisable
  48.     XREF    _LVOSupervisor
  49.     XREF    _LVOAutoRequest
  50.     XREF    _LVOFindTask
  51.     XREF    _LVOWaitPort
  52.     XREF    _LVOGetMsg
  53.     XREF    _LVOReplyMsg
  54.  
  55. ;
  56. ; ----- We are going to use the exec library for various things, so prepare
  57. ;    a pointer to it.
  58. ;
  59.  
  60.     movea.l    (_AbsExecBase).w,a6    ;Get pointer to exec library.
  61.  
  62. ;
  63. ; ----- First make sure the workbench message pointer is null,  then  check
  64. ;    to  see if we were started by the workbench or not.  If so, get the
  65. ;    startup message and save it away.
  66. ;
  67.  
  68.     clr.l    d5            ;Clear the message pointer.
  69.  
  70.     suba.l    a1,a1            ;Find our task.
  71.     jsr    _LVOFindTask(a6)    ; ..
  72.     movea.l    d0,a4            ; ..
  73.     tst.l    pr_CLI(a4)        ;See if we were run from CLI.
  74.     bne.s    RanFromCLI        ;If so, there's no message.
  75.  
  76.     lea    pr_MsgPort(a4),a0    ;Wait for the startup message.
  77.     jsr    _LVOWaitPort(a6)    ; ..
  78.     lea    pr_MsgPort(a4),a0    ;Get the startup message.
  79.     jsr    _LVOGetMsg(a6)        ; ..
  80.     move.l    d0,d5            ;Save it away.
  81.  
  82. ;
  83. ; ----- Now we must open the intuition library, since we intend to  use  it
  84. ;    to bring up a requester.
  85. ;
  86.  
  87. RanFromCLI:
  88.  
  89.     lea    IntuiLibName,a1        ;Point to library name.
  90.     moveq    #33,d0            ;Set the desired version.
  91.     jsr    _LVOOpenLibrary(a6)    ;Attempt to open the library.
  92.     tst.l    d0            ;See if the library opened ok.
  93.     bne.s    IntuiOpenedOk        ;If so, go on to other things.
  94.  
  95. ;
  96. ; ----- If we are here, the intuition library  failed  to  open.   This  is
  97. ;    unlikely,  since  it  is  ROM-resident,  so we do the easiest thing
  98. ;    possible to alert the user (besides not saying anything): bring  up
  99. ;    a RECOVERABLE alert, then exit the program.
  100. ;
  101.  
  102.     ALERT AG_OpenLib+AO_Intuition    ;Bring up the alert.
  103.     rts                ;Return to calling process.
  104.  
  105. ; -------------------------------------------------------------------------
  106.  
  107. ;
  108. ; ----- The intuition library  opened  ok.   Now,  since  cold-booting  the
  109. ;    machine is something of a drastic step, bring up a requester asking
  110. ;    if this is really the desired course of action.
  111. ;
  112.  
  113. IntuiOpenedOk:
  114.  
  115.     movea.l    d0,a6            ;Use the intuition library.
  116.  
  117.     suba.l    a0,a0            ;We don't have a window open.
  118.     lea    IT_AreYouSure,a1    ;Index text for the requester.
  119.     lea    IT_Yes,a2        ;Index text for positive button.
  120.     lea    IT_No,a3        ;Index text for negative button.
  121.     moveq    #0,d0            ;No special IDCMP flags.
  122.     moveq    #0,d1            ; ..
  123.     move.l    #300,d2            ;Set width of requester.
  124.     move.l    #70,d3            ;Set height of requester.
  125.     jsr    _LVOAutoRequest(a6)    ;Display and process the requester.
  126.  
  127. ;
  128. ; ----- If the return value was TRUE (go ahead and reboot), go on  to  more
  129. ;    exciting stuff; otherwise, close intuition and exit.
  130. ;
  131.  
  132.     tst.l    d0            ;See if user clicked "YES".
  133.     bne.s    DoReset            ;If so, go ahead and trash machine.
  134.  
  135.     movea.l    a6,a1            ;Otherwise, index library to close.
  136.     movea.l    (_AbsExecBase).w,a6    ;Use the exec library.
  137.     jsr    _LVOCloseLibrary(a6)    ;Close the intuition library.
  138.  
  139. ;
  140. ; ----- If we started from workbench, we  have  to  reply  to  the  startup
  141. ;    message before we exit.
  142. ;
  143.  
  144.     tst.l    d5            ;See if there was a message.
  145.     beq.s    NotWB            ;If not, just return.
  146.  
  147.     movea.l    d5,a1            ;Reply to workbench and exit
  148.     jmp    _LVOReplyMsg(a6)    ; ..
  149.  
  150.  
  151. NotWB:
  152.  
  153.     moveq    #0,d0            ;Set a good return value.
  154.     rts                ;Return to the calling process.
  155.  
  156. ; -------------------------------------------------------------------------
  157.  
  158. ;
  159. ; ----- Make sure the machine does a  completely  frigid  reboot.   If  the
  160. ;    checksum  of  ExecBase is wrong, the machine will assume all memory
  161. ;    is trashed, so we clear it.  Just to make extra sure, we also clear
  162. ;    the  pointers  to memory to preserve and modules to relink into the
  163. ;    system on a warm boot.  Note  that  we  DISABLE  interrupts  first,
  164. ;    since  once we get going here, other tasks on the machine will find
  165. ;    our actions most distressing.
  166. ;
  167.  
  168. DoReset:
  169.  
  170.     movea.l    (_AbsExecBase).w,a6    ;Use the exec library again.
  171.     jsr    _LVODisable(a6)        ;Stop everything else.
  172.  
  173.     moveq    #0,d0            ;Prepare to clear stuff.
  174.     move.l    d0,ChkBase(a6)        ;Trash the base complement.
  175.     move.l    d0,ColdCapture(a6)    ;Trash any coldboot vectors.
  176.     move.l    d0,ChkSum(a6)        ;Trash the ExecBase checksum.
  177.     move.l    d0,KickMemPtr(a6)    ;Trash recoverable memory locs.
  178.     move.l    d0,KickTagPtr(a6)    ;Trash ROMTAG list.
  179.     move.l    d0,KickCheckSum(a6)    ;Trash kickstart checksum.
  180.  
  181. ;
  182. ; ----- Now we actually reboot the machine.  Since  we  are  a  lowly  user
  183. ;    process,  we  must request the system to execute our reboot code in
  184. ;    supervisor mode.  This code, and the actual reset code below, comes
  185. ;    from  page  219  of the Amiga Hardware Reference Manual for version
  186. ;    1.3.
  187. ;
  188.  
  189.     movea.l    (_AbsExecBase).w,a6    ;Use the exec library.
  190.     lea.l    MagicResetCode(pc),a5    ;Point to the actual reset code.
  191.     jsr    _LVOSupervisor(a6)    ;Execute it.
  192.  
  193. ;
  194. ; ----- Since the reset code should NOT return, if we got  here,  there  is
  195. ;    something  bizzare  going  on.  Since we intended to reboot anyway,
  196. ;    bring up a fatal alert (a.k.a. the GURU).  Note that the alert code
  197. ;    is  somewhat  of  an improvision, since there isn't really a "reset
  198. ;    failed" alert.
  199. ;
  200.  
  201.     ALERT AT_DeadEnd+AN_BootError    ;Summon the GURU and die.
  202.  
  203. ; -------------------------------------------------------------------------
  204.  
  205. ;
  206. ; ----- This is the reset code itself, as documented on  page  219  of  the
  207. ;    Amiga  Hardware  Reference  Manual for version 1.3.  Note that this
  208. ;    code  MUST  be  executed  in  supervisor  mode,  since  the   RESET
  209. ;    instruction is not a user-mode instruction.
  210. ;
  211. ;    The reset code depends on two things: first, that when the  machine
  212. ;    is  reset,  the  ROM  image  is mapped to location $00000000 so the
  213. ;    680x0 processor will grab the reset vector  from  it;  and  second,
  214. ;    that  there  will  be  one instruction in the 680x0 internal cache,
  215. ;    since the RESET instruction makes all the memory go away!
  216. ;
  217.  
  218.     CNOP    0,4            ;Code MUST be longword aligned.
  219.  
  220. MagicResetCode:
  221.  
  222.     lea.l    2,a0            ;Index reset-vector-to-be.
  223.     reset                ;Reset the machine.
  224.     jmp    (a0)            ;Jump to the reset vector in ROM.
  225.  
  226. ; -------------------------------------------------------------------------
  227.  
  228. ;
  229. ; ----- Here are the IntuiText structures used for the requester.
  230. ;
  231.  
  232. IT_AreYouSure:
  233.  
  234.     dc.b    0,1            ;Front and back pens.
  235.     dc.b    RP_JAM1            ;Drawing mode.
  236.     dc.b    0            ;Filler...
  237.     dc.w    10,5            ;Position of text.
  238.     dc.l    0            ;Use default font.
  239.     dc.l    T_AreYouSure1        ;Pointer to text.
  240.     dc.l    IT_AreYouSure2        ;Link to more text.
  241.  
  242. IT_AreYouSure2:
  243.  
  244.     dc.b    0,1            ;Front and back pens.
  245.     dc.b    RP_JAM1            ;Drawing mode.
  246.     dc.b    0            ;Filler...
  247.     dc.w    10,15            ;Position of text.
  248.     dc.l    0            ;Use default font.
  249.     dc.l    T_AreYouSure2        ;Pointer to text.
  250.     dc.l    IT_AreYouSure3        ;Link to more text.
  251.  
  252. IT_AreYouSure3:
  253.  
  254.     dc.b    0,1            ;Front and back pens.
  255.     dc.b    RP_JAM1            ;Drawing mode.
  256.     dc.b    0            ;Filler...
  257.     dc.w    10,25            ;Position of text.
  258.     dc.l    0            ;Use default font.
  259.     dc.l    T_AreYouSure3        ;Pointer to text.
  260.     dc.l    0            ;No more text.
  261.  
  262. IT_Yes:
  263.  
  264.     dc.b    0,1            ;Front and back pens.
  265.     dc.b    RP_JAM1            ;Drawing mode.
  266.     dc.b    0            ;Filler...
  267.     dc.w    18,3            ;Position of text.
  268.     dc.l    0            ;Use default font.
  269.     dc.l    T_Yes            ;Pointer to text.
  270.     dc.l    0            ;No more text.
  271.  
  272. IT_No:
  273.  
  274.     dc.b    0,1            ;Front and back pens.
  275.     dc.b    RP_JAM1            ;Drawing mode.
  276.     dc.b    0            ;Filler...
  277.     dc.w    22,3            ;Position of text.
  278.     dc.l    0            ;Use default font.
  279.     dc.l    T_No            ;Pointer to text.
  280.     dc.l    0            ;No more text.
  281.  
  282. ;
  283. ; ----- All the actual text goes here, at the end of  the  program,  so  we
  284. ;    don't have to worry about alignment after we're done.
  285. ;
  286.  
  287. IntuiLibName:    dc.b    'intuition.library',0
  288.  
  289. T_AreYouSure1:    dc.b    'This program will COLD BOOT your',0
  290. T_AreYouSure2:    dc.b    'machine.   Are you sure you want',0
  291. T_AreYouSure3:    dc.b    'to do this?',0
  292.  
  293. T_Yes:        dc.b    'Yes   ',0
  294. T_No:        dc.b    'No    ',0
  295.  
  296.  
  297.     dc.b    '@(#) coldboot.a v1.03(0) 5-Mar-91 pdd',0
  298.  
  299.  
  300.     end
  301.